#include "qzeromenubar.h"

QZeroMenuBar::QZeroMenuBar()
{
  type_ = QZeroMenuBarTypeHorizontal;
  xinit_ = 5;
  yinit_ = 5;
  xsize_ = 40;
  ysize_ = 40;
  spacing_ = 10;
  hidden_ = false;
}

QZeroMenuBar::~QZeroMenuBar()
{

}

void QZeroMenuBar::addIcon(const QZeroIconProperties& prop)
{
  int x = xinit_;
  int y = yinit_;
  if (type_ == QZeroMenuBarTypeHorizontal)
  {
    x += (xsize_ + spacing_) * icons_.size();
  }
  else
  {
    y += (ysize_ + spacing_) * icons_.size();
  }
  QZeroIcon theIcon(prop);
  theIcon.Init(x, y ,xsize_, ysize_);
  icons_.push_back(theIcon);
}

void QZeroMenuBar::draw(unsigned int width, unsigned int height, int z)
{
  MenuBarIcons::iterator it;
  for (it=icons_.begin(); it!=icons_.end(); it++)
  {
    (*it).draw(width, height, z);
  }
}

void QZeroMenuBar::mouselocation(int x, int y)
{
  MenuBarIcons::iterator it;
  for (it=icons_.begin(); it!=icons_.end(); it++)
  {
    (*it).highlight(x, y);
  }

}

std::string QZeroMenuBar::action(int x, int y)
{
  MenuBarIcons::iterator it;
  for (it=icons_.begin(); it!=icons_.end(); it++)
  {
    if ((*it).highlight(x, y))
    {
      return((*it).prop().action());
    }
  }
  return(std::string("NULL"));
}

void QZeroMenuBar::press(int x, int y)
{
  MenuBarIcons::iterator it;
  for (it=icons_.begin(); it!=icons_.end(); it++)
  {
    (*it).press(x, y);
  }
}

void QZeroMenuBar::release(int x, int y)
{
  MenuBarIcons::iterator it;
  for (it=icons_.begin(); it!=icons_.end(); it++)
  {
    (*it).release(x, y);
  }
}

void QZeroMenuBar::setAlpha(float alpha)
{
  MenuBarIcons::iterator it;
  for (it=icons_.begin(); it!=icons_.end(); it++)
  {
    (*it).setAlpha(alpha);
  }
}

bool QZeroMenuBar::mouseInsideMenuBar(int x, int y)
{
  int maxx = 0, maxy = 0;
  if (type_ == QZeroMenuBarTypeHorizontal)
  {
    maxx = xinit_ + (xsize_ + spacing_) * icons_.size();
    maxy = yinit_ + ysize_;
  }
  else
  {
    maxx = xinit_ + xsize_;
    maxy = yinit_ + (ysize_ + spacing_) * icons_.size();
  }
  if (x > 0 && x < maxx && y > 0 && y < maxy)
  {
    return(true);
  }
  return(false);
}
